473,461 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C# Embedded font for button

Hello all,

I've added a font to my project and set it to "Embedded Resource".

I load the font into a global PrivateFontCollection. (InitCustomFont -
shown below)

I then set the font of a label to be equal to the custom font
(SetCustomFont - shown below)

The font size changes but the family doesn't. If I write directly to
the form using Graphics.DrawString the new font is displayed???

Does that mean I can't change the font of labels/buttons etc. to
resource fonts?

Gareth

private void InitCustomFont()
{
// Load the resource
Stream fontStream =
this.GetType().Assembly.GetManifestResourceStream( "Graphyx.custom.ttf");

// Create a buffer to read into
byte[] fontData = new byte[fontStream.Length];

// Fetch the font program from the resource
fontStream.Read(fontData, 0, (int)fontStream.Length);

unsafe
{
fixed (byte* pFontData = fontData)
{

// Pass the font to the font collection
pfc.AddMemoryFont((System.IntPtr)pFontData,
(int)fontStream.Length);
}
}
// Close the resource stream
fontStream.Close();
}

private void SetCustomFont()
{
System.Drawing.Font fn;
FontFamily ff;

ff = pfc.Families[0];

fn = new Font(ff, 16, FontStyle.Regular);

//lblHelp.Font = new System.Drawing.Font("Courier New", 16.0f,
(FontStyle)2);
lblHelp.Font = fn;
}

Feb 8 '06 #1
0 6470

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Colleyville Alan | last post by:
I have been working on an Access app that takes info from a file and writes it to a spreadsheet on a form, simultaneously saving the spreadsheet to Excel. I got the idea that the same concept...
2
by: Jim | last post by:
Working with VB.net under VS.Net 2003. Have a simple form with a Button1. I want to change the font on the button when the button is clicked. Is there a way to Dynamically change the Font for...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
1
by: Blasting Cap | last post by:
I am having trouble changing the font for a PushButton control in a datagrid button column. I have seen several posts refer to styles and simple changes to the HTML for font changes but most of...
1
by: erictomlinson | last post by:
I'm dying here trying to figure this out for days. Here's the scenario: 1) External script.as file dynamically imported to loader.swf file that creates a textfield (createTextField) 2)...
6
by: andrew.ames | last post by:
Hi I have a pretty basic windows application created in Visual Studio 2005 and VB.NET. I set my Form's font to Arial 8.25pt, so when i added a label and a button they automatically have a...
1
by: CMiner | last post by:
What I am trying to do is this: Let a user browse for font files that are not installed, select one, and show a sample of the font in a text box (That way the user can change the size, style, and...
0
by: =?Utf-8?B?Qm9iIFdhaXRl?= | last post by:
I have written a calculator emulator which uses an LCD font in VB.NET in VS2005. This application will be installed by means of an MSI file and I dont want the user to have to manually install the...
4
by: DamienS | last post by:
Hi, After many years of using html/css/asp etc for the first time I've had a requirement to use a custom font in a website. "That shouldn't be too hard" thought I, "that would be a pretty common...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.